<?php

/**
 * AdminModel 模型
 * Class AdminModel
 */
class AdminModel extends BaseModel
{
    public $tableName = "admin";
    public $errMsg = '';

    public $ruser;

    static private $_singleton;

    public function __construct()
    {
        parent::__construct($this->tableName);
    }

    static public function getSingleton()
    {
        if (!self::$_singleton) {
            self::$_singleton = new static();
        }

        return self::$_singleton;
    }

    /*
     *权限角色 1网店 2实体店 3平台超级管理
     * 权限值 1 无权限 0有权限
     */
    static public $permissions = [
        1   => [
            'user_shop'         => 1,
            'user_offlineshop'  => 1,
            'config'            => 1,
            'cate'              => 1,
            'speccats'          => 1,
            'product'           => 1,
            'purchase'          => 1,
            'purchase_log'      => 1,
            'cloud'             => 1,
            'apply_list'        => 1
        ],
        2   => [
            'user_offlineshop'  => 1,
            'config'            => 1,
            'cate'              => 1,
            'speccats'          => 1,
            'product'           => 1,
            'apply_list'        => 1
        ],
        3   => [
            'shop_product'      => 1,
            'reward'            => 1
        ]
    ];

    public function add($data)
    {
        try {
            $selfModel = static::getSingleton();
            return $selfModel->insert([
                'user_id'       => $data['user_id'],
                'admin_type'    => $data['admin_type'],
                'username'      => isset($data['username'])? $data['username']: '',
                'moble'         => isset($data['moble'])? $data['moble']: '',
                'password'      => $data['password'],
                'status'        => 1,
                'to_one_admin_id'   => isset($data['to_one_admin_id'])? $data['to_one_admin_id']: 0,
                'to_two_admin_id'   => isset($data['to_two_admin_id'])? $data['to_two_admin_id']: 0,
                'create_time'   => isset($data['create_time'])? $data['create_time']: time()
            ]);
        } catch (Exception $e) {
            $this->errMsg = $e->getMessage();
            return false;
        }
    }

}